package com.wmwj.hxlj.controller;

import com.wmwj.hxlj.entity.Comment;
import com.wmwj.hxlj.service.CommentService;
import com.wmwj.hxlj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/add")
    public Result<Comment> addComment(@RequestBody Comment comment) {
        return commentService.addComment(comment);
    }

    @DeleteMapping("/delete/{commentId}")
    public Result<String> deleteComment(@PathVariable Integer commentId){
        System.out.println(commentId);
        return commentService.deleteComment(commentId);
    }

    // 新增方法：获取对应文章的所有评论
    @GetMapping("/getByArticleId/{articleId}")
    public Result<List<Comment>> getCommentsByArticleId(@PathVariable Long articleId) {
        return commentService.getCommentsByArticleId(articleId);
    }

    //获取对应文章的所有父评论
    @GetMapping("/getParentComment/{articleId}")
    public Result<List<Comment>> getParentComments(@PathVariable Long articleId) {
        return commentService.getParentComments(articleId);
    }

    //获取对应父评论的所有子评论
    @GetMapping("/getChildComment/{parentId}")
    public Result<List<Comment>> getChildComments(@PathVariable Long parentId) {
        return commentService.getChildComments(parentId);
    }

    // 新增方法：点赞评论
    @GetMapping("/like/{commentId}")
    public Result<String> likeComment(@PathVariable Long commentId) {
        return commentService.likeComment(commentId);
    }

}